﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Compiler
{
    //A::= <B>
    //-> A ::= B S
    //   S ::= B S
    //   S ::= Epsilon
    public class EbnfAngleBracket : EbnfNode
    {
        EbnfNode node;

        public EbnfAngleBracket(EbnfNode node)
        {
            this.node = node;
        }

        static int cnt = 1;
        public override EbnfNode Expand(Stack<EbnfAssign> Open)
        {
            node = node.Expand(Open);

            EbnfMeta newMeta = new EbnfMeta(string.Format("X{0}", cnt++));

            EbnfConcat concat = new EbnfConcat(node, newMeta);
            EbnfAssign asn1 = new EbnfAssign(newMeta, new EbnfConcat(node, newMeta));
            EbnfAssign asn2 = new EbnfAssign(newMeta, new EbnfEpsilonNode());

            Open.Push(asn1);
            Open.Push(asn2);

            return concat;
        }

        public override string ToString()
        {
            return "<" + node.ToString() + ">";
        }
    }
}
